package com.example.redisdemo;

import org.redisson.cache.LRUCacheMap;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Jonathan
 * 2021/4/29 19:09
 * 操作jedis
 * 需求：
 * 1、输入手机号，点击发送后随机生成6位数字码，2分钟有效
 * 2、输入验证码，点击验证，返回成功或失败
 * 3、每个手机号每天只能输入3次
 */
public class JedisDemo {
    private static ShardedJedisPool pool;

    static {
        // 配置Redis信息
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(50);
        config.setMaxWaitMillis(3000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);

        // 集群
        JedisShardInfo jedisShardInfo1 = new JedisShardInfo("127.0.0.1", 6379);

        // 设置Redis的密码
        jedisShardInfo1.setPassword("root");

        List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
        list.add(jedisShardInfo1);
        pool = new ShardedJedisPool(config, list);
    }

    public static void main1(String[] args) {
        ShardedJedis jedis1 = pool.getResource();
        jedis1.set("test", "test");
        System.out.println(jedis1.get("test"));
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        //  认证
        jedis.auth("root");
        String test = jedis.ping("test");
        System.out.println(test);
//        jedis.sismember()
    }

    public static void main(String[] args) {
        LRUCacheMap<String, String> map = new LRUCacheMap<>(100, 100, 100);
        map.put("111","111");
        String s = map.get("111");
        System.out.println(s);

    }
}
